package com.springcloud.entity;

import lombok.Data;

/**
 * 错误返回实体类
 * @param <T> 返回数据对象
 */
@Data
public class ErrorMsg<T> {

    //错误码
    private Integer errorCode;

    //错误信息，一般为前端提示信息
    private String errorMsg;

    //返回值，一般为成功后返回的数据
    private T data;

    //错误详情，一般为失败后的详细原因，如空指针之类的
    private String errorDetail;

    public ErrorMsg() {}

    public ErrorMsg(Integer errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    /**
     * 配合静态对象，直接设置错误信息
     * @param error
     * @param errorMsg
     */
    public ErrorMsg(ErrorMsg error, String errorMsg) {
        error.setErrorDetail(errorMsg);
    }

    public static final ErrorMsg SUCCESS = new ErrorMsg(200, "成功");

    public static final ErrorMsg LOGIN_ERROR = new ErrorMsg(202, "登陆错误");

    public static final ErrorMsg LOGIN_EXPIRE = new ErrorMsg(202, "登陆过期");

    public static final ErrorMsg ACCESS_LIMITED = new ErrorMsg(301, "访问受限");

    public static final ErrorMsg ARGS_ERROR = new ErrorMsg(501, "参数错误");

    public static final ErrorMsg UNKOWN_ERROR = new ErrorMsg(502, "系统异常");

    public static final ErrorMsg INSERT_ERROR = new ErrorMsg(503, "新增错误");

    public static final ErrorMsg UPDATE_ERROR = new ErrorMsg(504, "更新错误");

    public static final ErrorMsg DELETE_ERROR = new ErrorMsg(506, "删除错误");

    public static final ErrorMsg UPLOAD_ERROR = new ErrorMsg(507, "上传错误");

    public static final ErrorMsg DOWNLOAD_ERROR = new ErrorMsg(508, "下载错误");
}
